function drawCode(img, _width, _height,imgClass) {
    //img:所有的图片数组
    //_width:canvas的宽度
    //_height:canvas的高度
    //imgClass:需要展示的图片的div容器

    var data = {image: img}, imgPath;
    var mycanvas = document.createElement('canvas')；
    document.body.appendChild(mycanvas);
    var len = data.image.length;
    mycanvas.width = _width;
    mycanvas.height = _height;

    if (mycanvas.getContext) {
        var context = mycanvas.getContext('2d');
        // 在canvas绘制前填充白色背景
        context.fillStyle = "#fff";
        context.fillRect(0, 0, mycanvas.width, mycanvas.height);

        // 宣传图片
        function drawing(num) {
            if (num < len) {
                var img = new Image;
                img.src = data.image[num];
                if (num == 0) {
                    img.onload = function () {
                        context.drawImage(img, 0, mycanvas.height * 0.16, mycanvas.width, mycanvas.height * 0.84);
                        drawing(num + 1);
                    }
                } else if (num == 1) {
                    img.onload = function () {
                        context.drawImage(img, mycanvas.width * 0.25, mycanvas.width * 0.3, mycanvas.width * 0.52, mycanvas.width * 0.52);
                        drawing(num + 1);
                    }
                } else if (num == 2) {
                    img.onload = function () {
                        //图片
                        context.drawImage(img, mycanvas.width * 0.29, 0, mycanvas.width * 0.28, mycanvas.height * 0.43);
                        drawing(num + 1);
                    }
                }
            } else {
                imgPath = mycanvas.toDataURL("image/jpeg");
                imgClass.attr('src', imgPath);
                $('canvas').remove();
            }
        }

        drawing(0);
    }
}

CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {
    var min_size = Math.min(w, h);
    if (r > min_size / 2) r = min_size / 2;
    // 开始绘制
    this.beginPath();
    this.moveTo(x + r, y);
    this.arcTo(x + w, y, x + w, y + h, r);
    this.arcTo(x + w, y + h, x, y + h, r);
    this.arcTo(x, y + h, x, y, r);
    this.arcTo(x, y, x + w, y, r);
    this.closePath();
    return this;
}
